﻿using Entitas;
using System.Linq;
class EnemyAttackSystem : IExecuteSystem
{
    EnemyContext enemyContext;
    public EnemyAttackSystem(Contexts contexts)
    {
        enemyContext = contexts.enemy;
    }
    public void Execute()
    {
        foreach (var e in enemyContext.GetEntities().Where(x => x.hasTargetInformation == true && x.isBattleEngaged == true))
        {
            if (!e.isAttacking)
            {
                e.isAttacking = true;
                var attacktime = 0f;
                ServiceManager.ViewService.InstantiateEnemyAttack(e.name.value,e.damage.value, e.position.value, e.direction.value);
                string enemyname = e.name.value.Remove(e.name.value.IndexOf(' '));
                switch (enemyname)
                {
                    case "Hornet":
                        attacktime = 3f;
                        break;
                    default:
                        break;
                }
                e.ReplaceAttackTimer(attacktime);
            }

        }
    }
}
